package com.security.domain.bo;

import jakarta.servlet.http.HttpServletResponse;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * business object
 * 业务对象
 * 用于封装返回给前端的数据
 *
 * @author DblSun
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class R<T> {
    int code;
    String message;
    T data;

    public static <T> R<T> success(String message, T data) {
        return new R<>(HttpServletResponse.SC_OK, message, data);
    }

    public static <T> R<T> success(String message) {
        return new R<>(HttpServletResponse.SC_OK, message, null);
    }

    public static <T> R<T> error(int code, String message) {
        return new R<>(code, message, null);
    }
}
